﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>通用数据字典列表</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/Plugin/om-yj-container.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript">
        var listGrid, colData = [], searchPanel, defaultSort, defaultWhere, currentUID, gridTitle, searchField, exportField, viewSql;
        var showSearchPanel, goOn = true;

        $(document).ready(function () {
            art.dialog.data("selectValue", 'undefined');
            $.ajax({
                cache: false, async: false,
                url: '../handler/commonselect.ashx?code='+art.dialog.data('SelectCode'),
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载配置信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    if (data.IsError) {
                        goOn = false;
                        $.omMessageBox.alert({
                            content: '发现系统错误,请重新登录<BR>错误码：' + data.Message,
                            onClose: function () {}
                        });
                    }
                    else {
                        goOn = true;
                        gridTitle = '选择' + data.Data.name;
                        searchField = data.Data.findField;
                        exportField = data.Data.exportField;
                        viewSql = data.Data.sqlField;
                        $(data.Data.dataField).each(function (index, value) {
                            colData.push({ header: value.header, name: value.name, width: parseInt(value.width), align: value.align });
                        })
                    }
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.alert({
                        content: '发现系统错误,请重新登录<BR>错误码：' + result.status,
                        onClose: function () {}
                    });
                }
            });

            if (goOn) {
                defaultSort = { sortby: 'UID', sortdir: 'ASC' };
                defaultWhere = { where: ' 1=2 ' };
                listGrid = $('#listgrid').omGrid({
                    width: '100%',
                    height: 300,
                    singleSelect: true,
                    onRowDblClick: function (rowIndex, rowData, event) {
                        art.dialog.data('selectValue',eval('rowData.'+exportField));
                        art.dialog.close();
                    },
                    limit: 10,
                    extraData: $.extend(defaultWhere, defaultSort),
                    dataSource: '../Handler/grid.ashx?view=('+ escape(viewSql) +') AS ',
                    colModel: colData
                });
                showSearchPanel();
            }
        });

        showSearchPanel = function () {
            $('span#button-search').omButton({
                icons: { left: '../Content/Images/List/search.png' }, width: 80,
                onClick: function (event) {
                    var custWhere = ' ';
                    if ($('#Content').val().length == 0) {
                        custWhere = ' 1=1 '
                    }
                    else {
                        var searcharr = searchField.split(',');
                        for (var i = 0, l = searcharr.length; i < l; i++) {
                            custWhere += " " + searcharr[i]  + ' LIKE ' + '\'%' + $('#Content').val() + '%\' ' + 'OR' ;
                        }
                        custWhere = custWhere.substring(0, custWhere.length - 2);
                    }
                    listGrid.omGrid({ extraData: $.extend({ where: custWhere }, defaultSort) });
                } 
            });
            $('span#button-clear').omButton({
                icons: { left: '../Content/Images/List/search.png' }, width: 80,
                onClick: function (event) {
                    $('#Content').val("");
                }
            });
            $('span#button-confirm').omButton({
                icons: { left: '../Content/Images/accept.png' }, width: 80,
                onClick: function (event) {
                    var selectRow = listGrid.omGrid("getSelections", true);
                    if (selectRow.length == 1) {
                        $.each(selectRow[0], function (index, value) {
                            if (index == exportField) {
                                art.dialog.data('selectValue', value);
                                return false;
                            }
                        })
                        art.dialog.close();
                    }
                    else {
                        $.omMessageBox.alert({
                            content: '请至少选择一条数据',
                            onClose: function () { }
                        });
                    }
                }
            });
        };
    </script>
</head>
<body>
    <div id="search-panel">
        <table>
            <tr>
                <td>
                    <span class="label">关键字：</span>
                    <input type="text" class="input-text" id="Content" />
                    <span id="button-search">搜索</span>
                    <span id="button-clear">清空</span>
                    <span id="button-confirm">确认</span>
                </td>
            </tr>
        </table>
    </div>
    <table id="listgrid"></table>
</body>
</html>
